(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  typeof define === 'function' && define.amd ? define(['hy5b/math/index', 'jquery', './index'], factory) :
  factory(math, $);
}(this, function (util, $) { 'use strict';

  $.defineGd2d({
    name: 'drawLine',
    props: {
      scale: 1,
      dashLine: 0,
      strokeStyle: '',
      fillStyle: '',
      lineWidth: 1,
      lineCap: 'square',
      shadowColor: '',
      shadowBlur: '',
      offset: {
        x: 0,
        y: 0
      }
    },
    fn: function(ctx, p) {
      if (!p.acceptSave) {
        ctx.save();
        ctx.beginPath();
      }

      var points = p.points;
      var scale = p.scale;
      var dashLine = p.dashLine;
      var offset = p.offset;

      ctx.strokeStyle = p.strokeStyle;
      ctx.fillStyle = p.fillStyle;
      ctx.lineWidth = p.lineWidth;
      ctx.lineCap = p.lineCap;
      ctx.shadowColor = p.shadowColor;
      ctx.shadowBlur = p.shadowBlur;
      ctx.translate(offset.x, offset.y)

      if (p.lineDash) {
        ctx.setLineDash(p.lineDash)
        ctx.lineDashOffset = p.lineDashOffset;
      }

      ctx.moveTo(points[0][0] * scale, points[0][1] * scale);
      for (let i = 1; i < points.length; i++) {
        if (dashLine === 0) {
          ctx.lineTo(points[i][0] * scale, points[i][1] * scale);
        } else {
          drawDashLine(ctx, points[i - 1][0] * scale, points[i - 1][1] * scale,
            points[i][0] * scale, points[i][1] * scale, dashLine);
        }
      }
      if (p.strokeStyle && p.lineWidth) {
        ctx.stroke();
      }
      if (p.fillStyle) {
        ctx.fill();
      }

      ctx.closePath();
      ctx.restore();
    }
  });
  return $.defineGd2d;

}))